using UnityEngine;

public class RefereeStatePlaying : State<Referee>
{
	private static RefereeStatePlaying instance;

	private RefereeStatePlaying()
	{
	}

	public static RefereeStatePlaying getInstance()
	{
		if (instance == null)
		{
			instance = new RefereeStatePlaying();
		}
		return instance;
	}

	public override void fixedUpdate(Referee owner)
	{
		base.fixedUpdate(owner);
		Vector3 position = owner.getPosition();
		if (position.x < 8.1f)
		{
			GameHelper.MoveTo(owner, MathHelper.setX(owner.getPosition(), 8.2f), Global.MaxMoveSpeed_Referee, isLookAtTargetPos: true);
			owner.playAnimation(AnimationName.referee_run, 1f, -1f);
			return;
		}
		Vector3 cameraPos = Instance<CameraController>.instance.getCameraPos();
		if (cameraPos.z >= 0f)
		{
			Vector3 position2 = owner.getPosition();
			float num = position2.z - 1f;
			Vector3 cameraPos2 = Instance<CameraController>.instance.getCameraPos();
			if (Mathf.Abs(num - cameraPos2.z) > 0.5f)
			{
				goto IL_00fd;
			}
		}
		Vector3 cameraPos3 = Instance<CameraController>.instance.getCameraPos();
		if (cameraPos3.z < 0f)
		{
			Vector3 position3 = owner.getPosition();
			float num2 = position3.z + 1f;
			Vector3 cameraPos4 = Instance<CameraController>.instance.getCameraPos();
			if (Mathf.Abs(num2 - cameraPos4.z) > 0.5f)
			{
				goto IL_00fd;
			}
		}
		owner.playAnimation(AnimationName.referee_idle, 1f, 0.3f);
		owner.LookAt(MathHelper.setY(Instance<Ball>.instance.getPosition(), 0f));
		return;
		IL_00fd:
		Vector3 position4 = owner.getPosition();
		float x = position4.x;
		Vector3 cameraPos5 = Instance<CameraController>.instance.getCameraPos();
		float z;
		if (cameraPos5.z >= 0f)
		{
			Vector3 cameraPos6 = Instance<CameraController>.instance.getCameraPos();
			z = cameraPos6.z + 1f;
		}
		else
		{
			Vector3 cameraPos7 = Instance<CameraController>.instance.getCameraPos();
			z = cameraPos7.z - 1f;
		}
		if (GameHelper.MoveTo(owner, new Vector3(x, 0f, z), Global.MaxMoveSpeed_Referee, isLookAtTargetPos: true))
		{
			owner.playAnimation(AnimationName.referee_idle, 1f, 0.3f);
			owner.LookAt(MathHelper.setY(Instance<Ball>.instance.getPosition(), 0f));
		}
		else
		{
			owner.playAnimation(AnimationName.referee_run, 1f, 0.3f);
		}
	}
}
